package com.grsu.phonestation.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.grsu.phonestation.dao.ServiceDAO;
import com.grsu.phonestation.dao.impl.base.AbstractHibernateDAO;
import com.grsu.phonestation.domain.Service;

@Repository
public class ServiceDAOImpl<S extends Service> extends
		AbstractHibernateDAO<S, Integer> implements ServiceDAO<S> {

	@SuppressWarnings("unchecked")
	protected Class<S> getGenericEntityClass() {
		return (Class<S>) Service.class;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public S findById(Integer serviceId) {
		Criteria criteria = getSession().createCriteria(
				this.getGenericEntityClass(), "service").add(
				Restrictions.eq("id", serviceId));
		return (S) criteria.uniqueResult();
	}

}
